package com.uestc.shop.service.impl;

import com.uestc.shop.dao.UserRepository;
import com.uestc.shop.domain.User;
import com.uestc.shop.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Package: com.uestc.shop.service.impl
 * @author: hujiansong
 * @date: 2018/7/26 10:24
 * @version: V1.0
 */
@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    UserRepository userRepository;

    @Override
    public User findUserByName(String loginName) {
        User user = userRepository.findUserByUsername(loginName);
        if (user == null) {
            return null;
        }
        return user;
    }

    @Override
    public User save(User user) {
        User entity = userRepository.save(user);
        if (entity.getId() > 0) {
            return entity;
        } else {
            return null;
        }
    }

    @Override
    public User findUserById(int id) {
        User user = userRepository.findOne(id);
        return user;
    }
}
